package com.liujun.spring4.demo.aop.iocset.annotation.autowired.list;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author liujun
 * @version 1.0
 * @date 2018-08-19 16:18:00
 */
@Component
public class MyComponent {

  /** spring会将容器中所有类型为Plugin的bean注入这个变量 */
  private List<Plugin> plugins;

  /** 将plugin类型的bean注入Map中 */
  private Map<String, Plugin> pluginMaps;

  public List<Plugin> getPlugins() {
    return plugins;
  }

  public Map<String, Plugin> getPluginMaps() {
    return pluginMaps;
  }

  public void runList() {
    for (Plugin s : plugins) {
      s.addPlugin("currs");
    }
  }

  public void runMap() {
    for (Map.Entry<String, Plugin> s : pluginMaps.entrySet()) {
      System.out.println("s key :" + s.getKey() + ",value:" + s.getValue());
      s.getValue().addPlugin("curr map");
    }
  }

  @Autowired
  public void setPlugins(List<Plugin> plugins) {
    this.plugins = plugins;
  }

  @Autowired
  public void setPluginMaps(Map<String, Plugin> pluginMaps) {
    this.pluginMaps = pluginMaps;
  }
}
